#!/usr/bin/env python2.5 


#from nmpacks.milonpy  import NMserver

from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import webapp
 
#zipfile = None   
#flagsFile =  None #   zipfile.ZipFile("res/flagsres.zip", "r")  

class reqErr(webapp.RequestHandler): 
    def get(self, arg):    
        print 'CDS ERROR REQ' + arg  
# http://www.geognos.com/api/en/countries/flag/GR.png
class FlagReqHandler(webapp.RequestHandler):   
    def get(self, cntr, size): 
        url="%s%s%s%s" %(self.request.host_url, "/api/en/countries/flag/", cntr.upper(), ".png")
        #self.response.out.write (url)
        self.redirect(url, permanent=True) 

#class cdsReqHandler(NMserver.ReqHadlerNM):   
#    useCashe = 4
#    def Responce_ContentType(self) :return 'image/png'
#    def getC(self, cntr, size): 
#        global zipfile
#        global flagsFile
#        if zipfile is None:
#           import zipfile
#           flagsFile = zipfile.ZipFile("res/flagsres.zip", "r")  
#        ccflag= size+'_'+ cntr +'.png'  
#        try :
#          ccflag=flagsFile.read(ccflag)  
#        except :
#          self.error(400) 
#          return ''     
#        #self.response.headers['Last-Modified']   = (datetime.datetime.utcnow()+datetime.timedelta(-10)).strftime('%a, %d %b %Y %H:%M:%S GMT') 
#        #self.response.headers['Expires']  = (datetime.datetime.utcnow()+datetime.timedelta(1)).strftime('%a, %d %b %Y %H:%M:%S GMT') 
#        #self.response.headers['Cache-Control']  = 'public, max-age=86400'  ## 60*60*24
#        #self.response.headers['Content-Type'] = 'image/png'  
#        #print  'xxxxxxxxxxxxx ' * 100,  type (ccflag)
#        return ccflag
       

application = webapp.WSGIApplication(
                             [  
                              (r'/cds/en/flag/(..)/(.*)/', FlagReqHandler), 
                              ('(.*)', reqErr)
                              ],
                             debug=False)

def main():
    run_wsgi_app(application)
if __name__ == "__main__":
    main() 
